package com.example.demo.dao;

import com.example.demo.model.favourite;
import org.apache.ibatis.jdbc.SQL;

public class favouriteSqlProvider {

    /**
     * 根据字段是否为空保存 
     * @param record favourite
     * @return String
     */
    public String insertSelective(favourite record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("favourite");
        
        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getUserId() != null) {
            sql.VALUES("user_id", "#{userId,jdbcType=INTEGER}");
        }
        
        if (record.getNewsId() != null) {
            sql.VALUES("news_id", "#{newsId,jdbcType=INTEGER}");
        }
        
        if (record.getCollTime() != null) {
            sql.VALUES("coll_time", "#{collTime,jdbcType=DATETIME}");
        }
        
        return sql.toString();
    }

    /**
     * 根据字段是否为空更新 
     * @param record favourite
     * @return String
     */
    public String updateByPrimaryKeySelective(favourite record) {
        SQL sql = new SQL();
        sql.UPDATE("favourite");
        
        if (record.getUserId() != null) {
            sql.SET("user_id = #{userId,jdbcType=INTEGER}");
        }
        
        if (record.getNewsId() != null) {
            sql.SET("news_id = #{newsId,jdbcType=INTEGER}");
        }
        
        if (record.getCollTime() != null) {
            sql.SET("coll_time = #{collTime,jdbcType=DATETIME}");
        }
        
        sql.WHERE("id = #{id,jdbcType=INTEGER}");
        
        return sql.toString();
    }
}